package org.edu.modules.weights.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import java.util.List;
import java.util.Map;
import org.edu.modules.center.Bo.VeTeachWeightsBo;
import org.edu.modules.veTeachCourse.entity.VeTeachCourse;
import org.edu.modules.veTeachCourse.service.IVeTeachCourseService;
import org.edu.modules.weights.entity.VeTeachWeights;
import org.edu.modules.weights.mapper.VeTeachWeightsMapper;
import org.edu.modules.weights.service.IVeTeachWeightsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class VeTeachWeightsServiceImpl
        extends ServiceImpl<VeTeachWeightsMapper, VeTeachWeights>
        implements IVeTeachWeightsService
{
    @Autowired
    VeTeachWeightsMapper veTeachWeightsMapper;
    @Autowired
    IVeTeachWeightsService veTeachWeightsService;
    @Autowired
    IVeTeachCourseService veTeachCourseService;

    public String stopAdmin(List<Integer> ids)
    {
        return null;
    }

    public boolean updateById(List<VeTeachWeights> veTeachWeightsList, VeTeachCourse veTeachCourse)
    {
        for (int i = 0; i < veTeachWeightsList.size(); i++)
        {
            int weightId = ((VeTeachWeights)veTeachWeightsList.get(i)).getId().intValue();
            if (veTeachWeightsList.size() > 0)
            {
                boolean we = this.veTeachWeightsService.removeByWeightId(weightId);
                if (!we) {
                    return false;
                }
                boolean ret = this.veTeachWeightsService.saveBatch(veTeachWeightsList);
                if (!ret) {
                    return false;
                }
            }
            VeTeachCourse veTeachCourse1 = this.veTeachCourseService.getByWeightId(weightId);
            if (veTeachCourse == null)
            {
                boolean retWe = this.veTeachCourseService.saveSouce(veTeachCourse);
                if (!retWe) {
                    return false;
                }
            }
            else
            {
                boolean retWe = this.veTeachCourseService.updateById(veTeachCourse);
                if (!retWe) {
                    return false;
                }
            }
        }
        return true;
    }

    public boolean removeByWeightId(int weightId)
    {
        return SqlHelper.retBool(this.veTeachWeightsMapper.deleteByWeightId(weightId));
    }

    public List<VeTeachWeightsBo> selectWeight(Map<String, Object> params)
    {
        return this.veTeachWeightsMapper.selectWeight(params);
    }
}
